package cn.funnyxb.powerremember.uis.task.taskEdit.alarm;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.KeyguardManager;
import android.app.KeyguardManager.KeyguardLock;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.res.Resources;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.Vibrator;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import cn.funnyxb.powerremember.LogoActivity;
import cn.funnyxb.powerremember.beans.ATask;
import cn.funnyxb.powerremember.beans.AlarmInfo;
import com.mobclick.android.MobclickAgent;
import java.io.IOException;
import java.util.Calendar;

public class NotifyActivity extends Activity
  implements View.OnClickListener
{
  public static final String EXTRANAME_STATE = "state";
  public static final int STATE_NOTRUN = 3;
  public static final int STATE_RUNNING_BACK = 2;
  public static final int STATE_RUNNING_FRONT = 1;
  private boolean D = true;
  private ATask aTask = null;
  private AlarmInfo ai = null;
  private long alarmLen = 0L;
  private boolean isAlarming;
  private boolean isLocking;
  private KeyguardManager.KeyguardLock keyguardLock = null;
  private MediaPlayer player = null;
  private int resumeTimes;
  private int state;
  private int surpassGroupNum;
  private String tag = "notify";
  private Vibrator vibrator = null;

  private void alarm()
  {
    this.isAlarming = true;
    this.alarmLen = 0L;
    Uri localUri = RingtoneManager.getActualDefaultRingtoneUri(this, 4);
    if ((this.ai.getAlarmType() == 2) || (this.ai.getAlarmType() == 1))
      this.player = new MediaPlayer();
    try
    {
      this.player.setDataSource(this, localUri);
      this.player.prepare();
      this.player.start();
      this.player.setOnCompletionListener(new 1(this));
      if ((this.ai.getAlarmType() == 2) || (this.ai.getAlarmType() == 0))
      {
        long[] arrayOfLong = new long[240];
        arrayOfLong[0] = 300L;
        arrayOfLong[1] = 500L;
        arrayOfLong[2] = 400L;
        arrayOfLong[3] = 500L;
        arrayOfLong[4] = 300L;
        arrayOfLong[5] = 500L;
        arrayOfLong[6] = 400L;
        arrayOfLong[7] = 500L;
        arrayOfLong[8] = 300L;
        arrayOfLong[9] = 500L;
        arrayOfLong[10] = 400L;
        arrayOfLong[11] = 500L;
        arrayOfLong[12] = 300L;
        arrayOfLong[13] = 500L;
        arrayOfLong[14] = 400L;
        arrayOfLong[15] = 500L;
        arrayOfLong[16] = 300L;
        arrayOfLong[17] = 500L;
        arrayOfLong[18] = 400L;
        arrayOfLong[19] = 500L;
        arrayOfLong[20] = 300L;
        arrayOfLong[21] = 500L;
        arrayOfLong[22] = 400L;
        arrayOfLong[23] = 500L;
        arrayOfLong[24] = 300L;
        arrayOfLong[25] = 500L;
        arrayOfLong[26] = 400L;
        arrayOfLong[27] = 500L;
        arrayOfLong[28] = 300L;
        arrayOfLong[29] = 500L;
        arrayOfLong[30] = 400L;
        arrayOfLong[31] = 500L;
        arrayOfLong[32] = 300L;
        arrayOfLong[33] = 500L;
        arrayOfLong[34] = 400L;
        arrayOfLong[35] = 500L;
        arrayOfLong[36] = 300L;
        arrayOfLong[37] = 500L;
        arrayOfLong[38] = 400L;
        arrayOfLong[39] = 500L;
        arrayOfLong[40] = 300L;
        arrayOfLong[41] = 500L;
        arrayOfLong[42] = 400L;
        arrayOfLong[43] = 500L;
        arrayOfLong[44] = 300L;
        arrayOfLong[45] = 500L;
        arrayOfLong[46] = 400L;
        arrayOfLong[47] = 500L;
        arrayOfLong[48] = 300L;
        arrayOfLong[49] = 500L;
        arrayOfLong[50] = 400L;
        arrayOfLong[51] = 500L;
        arrayOfLong[52] = 300L;
        arrayOfLong[53] = 500L;
        arrayOfLong[54] = 400L;
        arrayOfLong[55] = 500L;
        arrayOfLong[56] = 300L;
        arrayOfLong[57] = 500L;
        arrayOfLong[58] = 400L;
        arrayOfLong[59] = 500L;
        arrayOfLong[60] = 300L;
        arrayOfLong[61] = 500L;
        arrayOfLong[62] = 400L;
        arrayOfLong[63] = 500L;
        arrayOfLong[64] = 300L;
        arrayOfLong[65] = 500L;
        arrayOfLong[66] = 400L;
        arrayOfLong[67] = 500L;
        arrayOfLong[68] = 300L;
        arrayOfLong[69] = 500L;
        arrayOfLong[70] = 400L;
        arrayOfLong[71] = 500L;
        arrayOfLong[72] = 300L;
        arrayOfLong[73] = 500L;
        arrayOfLong[74] = 400L;
        arrayOfLong[75] = 500L;
        arrayOfLong[76] = 300L;
        arrayOfLong[77] = 500L;
        arrayOfLong[78] = 400L;
        arrayOfLong[79] = 500L;
        arrayOfLong[80] = 300L;
        arrayOfLong[81] = 500L;
        arrayOfLong[82] = 400L;
        arrayOfLong[83] = 500L;
        arrayOfLong[84] = 300L;
        arrayOfLong[85] = 500L;
        arrayOfLong[86] = 400L;
        arrayOfLong[87] = 500L;
        arrayOfLong[88] = 300L;
        arrayOfLong[89] = 500L;
        arrayOfLong[90] = 400L;
        arrayOfLong[91] = 500L;
        arrayOfLong[92] = 300L;
        arrayOfLong[93] = 500L;
        arrayOfLong[94] = 400L;
        arrayOfLong[95] = 500L;
        arrayOfLong[96] = 300L;
        arrayOfLong[97] = 500L;
        arrayOfLong[98] = 400L;
        arrayOfLong[99] = 500L;
        arrayOfLong[100] = 300L;
        arrayOfLong[101] = 500L;
        arrayOfLong[102] = 400L;
        arrayOfLong[103] = 500L;
        arrayOfLong[104] = 300L;
        arrayOfLong[105] = 500L;
        arrayOfLong[106] = 400L;
        arrayOfLong[107] = 500L;
        arrayOfLong[108] = 300L;
        arrayOfLong[109] = 500L;
        arrayOfLong[110] = 400L;
        arrayOfLong[111] = 500L;
        arrayOfLong[112] = 300L;
        arrayOfLong[113] = 500L;
        arrayOfLong[114] = 400L;
        arrayOfLong[115] = 500L;
        arrayOfLong[116] = 300L;
        arrayOfLong[117] = 500L;
        arrayOfLong[118] = 400L;
        arrayOfLong[119] = 500L;
        arrayOfLong[120] = 300L;
        arrayOfLong[121] = 500L;
        arrayOfLong[122] = 400L;
        arrayOfLong[123] = 500L;
        arrayOfLong[124] = 300L;
        arrayOfLong[125] = 500L;
        arrayOfLong[126] = 400L;
        arrayOfLong[127] = 500L;
        arrayOfLong[128] = 300L;
        arrayOfLong[129] = 500L;
        arrayOfLong[130] = 400L;
        arrayOfLong[131] = 500L;
        arrayOfLong[132] = 300L;
        arrayOfLong[133] = 500L;
        arrayOfLong[134] = 400L;
        arrayOfLong[135] = 500L;
        arrayOfLong[136] = 300L;
        arrayOfLong[137] = 500L;
        arrayOfLong[138] = 400L;
        arrayOfLong[139] = 500L;
        arrayOfLong[140] = 300L;
        arrayOfLong[141] = 500L;
        arrayOfLong[142] = 400L;
        arrayOfLong[143] = 500L;
        arrayOfLong[144] = 300L;
        arrayOfLong[145] = 500L;
        arrayOfLong[146] = 400L;
        arrayOfLong[147] = 500L;
        arrayOfLong[148] = 300L;
        arrayOfLong[149] = 500L;
        arrayOfLong[150] = 400L;
        arrayOfLong[151] = 500L;
        arrayOfLong[152] = 300L;
        arrayOfLong[153] = 500L;
        arrayOfLong[154] = 400L;
        arrayOfLong[155] = 500L;
        arrayOfLong[156] = 300L;
        arrayOfLong[157] = 500L;
        arrayOfLong[158] = 400L;
        arrayOfLong[159] = 500L;
        arrayOfLong[160] = 300L;
        arrayOfLong[161] = 500L;
        arrayOfLong[162] = 400L;
        arrayOfLong[163] = 500L;
        arrayOfLong[164] = 300L;
        arrayOfLong[165] = 500L;
        arrayOfLong[166] = 400L;
        arrayOfLong[167] = 500L;
        arrayOfLong[168] = 300L;
        arrayOfLong[169] = 500L;
        arrayOfLong[170] = 400L;
        arrayOfLong[171] = 500L;
        arrayOfLong[172] = 300L;
        arrayOfLong[173] = 500L;
        arrayOfLong[174] = 400L;
        arrayOfLong[175] = 500L;
        arrayOfLong[176] = 300L;
        arrayOfLong[177] = 500L;
        arrayOfLong[178] = 400L;
        arrayOfLong[179] = 500L;
        arrayOfLong[180] = 300L;
        arrayOfLong[181] = 500L;
        arrayOfLong[182] = 400L;
        arrayOfLong[183] = 500L;
        arrayOfLong[184] = 300L;
        arrayOfLong[185] = 500L;
        arrayOfLong[186] = 400L;
        arrayOfLong[187] = 500L;
        arrayOfLong[188] = 300L;
        arrayOfLong[189] = 500L;
        arrayOfLong[190] = 400L;
        arrayOfLong[191] = 500L;
        arrayOfLong[192] = 300L;
        arrayOfLong[193] = 500L;
        arrayOfLong[194] = 400L;
        arrayOfLong[195] = 500L;
        arrayOfLong[196] = 300L;
        arrayOfLong[197] = 500L;
        arrayOfLong[198] = 400L;
        arrayOfLong[199] = 500L;
        arrayOfLong[200] = 300L;
        arrayOfLong[201] = 500L;
        arrayOfLong[202] = 400L;
        arrayOfLong[203] = 500L;
        arrayOfLong[204] = 300L;
        arrayOfLong[205] = 500L;
        arrayOfLong[206] = 400L;
        arrayOfLong[207] = 500L;
        arrayOfLong[208] = 300L;
        arrayOfLong[209] = 500L;
        arrayOfLong[210] = 400L;
        arrayOfLong[211] = 500L;
        arrayOfLong[212] = 300L;
        arrayOfLong[213] = 500L;
        arrayOfLong[214] = 400L;
        arrayOfLong[215] = 500L;
        arrayOfLong[216] = 300L;
        arrayOfLong[217] = 500L;
        arrayOfLong[218] = 400L;
        arrayOfLong[219] = 500L;
        arrayOfLong[220] = 300L;
        arrayOfLong[221] = 500L;
        arrayOfLong[222] = 400L;
        arrayOfLong[223] = 500L;
        arrayOfLong[224] = 300L;
        arrayOfLong[225] = 500L;
        arrayOfLong[226] = 400L;
        arrayOfLong[227] = 500L;
        arrayOfLong[228] = 300L;
        arrayOfLong[229] = 500L;
        arrayOfLong[230] = 400L;
        arrayOfLong[231] = 500L;
        arrayOfLong[232] = 300L;
        arrayOfLong[233] = 500L;
        arrayOfLong[234] = 400L;
        arrayOfLong[235] = 500L;
        arrayOfLong[236] = 300L;
        arrayOfLong[237] = 500L;
        arrayOfLong[238] = 400L;
        arrayOfLong[239] = 500L;
        this.vibrator = ((Vibrator)getSystemService("vibrator"));
        this.vibrator.vibrate(arrayOfLong, -1);
      }
      return;
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
      localIllegalArgumentException.printStackTrace();
    }
    catch (SecurityException localSecurityException)
    {
      localSecurityException.printStackTrace();
    }
    catch (IllegalStateException localIllegalStateException)
    {
      localIllegalStateException.printStackTrace();
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
  }

  private void alarmLater()
  {
    Toast.makeText(this, 2131034282, 0).show();
    AlarmManager localAlarmManager = (AlarmManager)getSystemService("alarm");
    Calendar.getInstance().setTimeInMillis(System.currentTimeMillis());
    Intent localIntent = new Intent(this, AlarmReceiver.class);
    localIntent.putExtra("alarminfo", this.ai);
    PendingIntent localPendingIntent = PendingIntent.getBroadcast(this, -1 * this.ai.get_id(), localIntent, 0);
    localAlarmManager.set(0, 600000L + System.currentTimeMillis(), localPendingIntent);
  }

  private void initFrame()
  {
    findViewById(2131165194).setBackgroundResource(17301525);
    ((TextView)findViewById(2131165193)).setText("  " + getString(2131034112) + getString(2131034275));
    ((ImageView)findViewById(2131165192)).setBackgroundResource(2130837504);
    ((ImageView)findViewById(2131165195)).setBackgroundDrawable(getResources().getDrawable(2130837505));
    findViewById(2131165197).setBackgroundResource(17301521);
    Button localButton1 = (Button)findViewById(2131165201);
    Button localButton2 = (Button)findViewById(2131165202);
    Button localButton3 = (Button)findViewById(2131165203);
    localButton1.setOnClickListener(this);
    localButton2.setOnClickListener(this);
    localButton3.setOnClickListener(this);
    label168: TextView localTextView3;
    StringBuilder localStringBuilder;
    if (this.state == 1)
    {
      localButton2.setVisibility(8);
      localButton3.setVisibility(8);
      if (this.isLocking)
        localButton3.setVisibility(8);
      TextView localTextView1 = (TextView)findViewById(2131165196);
      TextView localTextView2 = (TextView)findViewById(2131165198);
      localTextView3 = (TextView)findViewById(2131165199);
      String str1 = this.ai.getMemo();
      if ((str1 == null) || (str1.trim().length() == 0))
        str1 = AlarmOils.getRandom(this);
      localTextView1.setText(str1);
      localTextView2.setText(getString(2131034148) + "：" + this.aTask.getName());
      localStringBuilder = new StringBuilder(String.valueOf(getString(2131034276))).append("：");
      if (this.surpassGroupNum <= 0)
        break label390;
    }
    for (String str2 = getString(2131034277); ; str2 = getString(2131034278))
    {
      localTextView3.setText(str2 + Math.abs(this.surpassGroupNum) + getString(2131034149));
      return;
      if (this.state == 2);
      localButton3.setVisibility(8);
      label390: break label168:
    }
  }

  private void stopAlarm()
  {
    Log.i("notify", "call stop alarm");
    if (this.vibrator != null)
      this.vibrator.cancel();
    try
    {
      if (this.player != null)
      {
        if (this.player.isPlaying())
          this.player.stop();
        this.player.release();
      }
      this.isAlarming = false;
      return;
    }
    catch (Exception localException)
    {
    }
  }

  public void onClick(View paramView)
  {
    switch (paramView.getId())
    {
    default:
    case 2131165203:
    case 2131165202:
    case 2131165201:
    }
    while (true)
    {
      return;
      stopAlarm();
      Intent localIntent = new Intent(this, LogoActivity.class);
      if ((this.isLocking) && (this.keyguardLock != null))
      {
        this.keyguardLock.reenableKeyguard();
        this.keyguardLock = null;
      }
      startActivity(localIntent);
      finish();
      continue;
      stopAlarm();
      alarmLater();
      if ((this.isLocking) && (this.keyguardLock != null))
      {
        this.keyguardLock.reenableKeyguard();
        this.keyguardLock = null;
      }
      finish();
      continue;
      stopAlarm();
      if ((this.isLocking) && (this.keyguardLock != null))
      {
        this.keyguardLock.reenableKeyguard();
        this.keyguardLock = null;
      }
      finish();
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    PowerManager.WakeLock localWakeLock = ((PowerManager)getSystemService("power")).newWakeLock(268435462, "SimpleTimer");
    localWakeLock.acquire();
    localWakeLock.release();
    this.resumeTimes = 0;
    KeyguardManager localKeyguardManager = (KeyguardManager)getSystemService("keyguard");
    this.isLocking = localKeyguardManager.inKeyguardRestrictedInputMode();
    Log.i(this.tag, "notfy create,islocking=" + this.isLocking);
    if (this.isLocking)
    {
      this.keyguardLock = localKeyguardManager.newKeyguardLock("");
      this.keyguardLock.disableKeyguard();
    }
    requestWindowFeature(1);
    Intent localIntent = getIntent();
    this.ai = ((AlarmInfo)localIntent.getSerializableExtra("alarminfo"));
    this.aTask = ((ATask)localIntent.getSerializableExtra("taskinfo"));
    this.state = localIntent.getExtras().getInt("state");
    this.surpassGroupNum = localIntent.getExtras().getInt("surpassgroupnum");
    if (this.D)
      Log.i(this.tag, "start taskedit oncreate,ai=" + this.ai);
    if ((this.ai == null) || ((0x100000 & localIntent.getFlags()) != 0))
    {
      startActivity(new Intent(this, LogoActivity.class));
      finish();
    }
    while (true)
    {
      return;
      setContentView(2130903043);
      initFrame();
      alarm();
    }
  }

  public void onDestroy()
  {
    try
    {
      finalize();
      Log.i("notify", "call ondestroy");
      super.onDestroy();
      return;
    }
    catch (Throwable localThrowable)
    {
      localThrowable.printStackTrace();
    }
  }

  public void onPause()
  {
    super.onPause();
    MobclickAgent.onPause(this);
  }

  public void onResume()
  {
    super.onResume();
    MobclickAgent.onResume(this);
    this.resumeTimes = (1 + this.resumeTimes);
  }

  public void onStop()
  {
    super.onStop();
    if ((this.isAlarming) && (((!(this.isLocking)) || (this.resumeTimes >= 2))))
      stopAlarm();
    if ((!(this.isLocking)) || (this.keyguardLock == null))
      return;
    this.keyguardLock.reenableKeyguard();
    if (this.isAlarming)
      stopAlarm();
    finish();
  }
}

/* Location:           E:\Desktop\复件 classes_dex2jar.jar
 * Qualified Name:     cn.funnyxb.powerremember.uis.task.taskEdit.alarm.NotifyActivity
 * JD-Core Version:    0.5.3
 */